package com.heifeng.cloudshelf.mvp.programme.provider;

import android.content.Context;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.heifeng.cloudshelf.R;
import com.heifeng.cloudshelf.mvp.model.ProgrammeSelectInfo;
import com.heifeng.cloudshelf.mvp.model.SpecMultipleEntity;
import com.heifeng.cloudshelf.mvp.programme.adapter.SpecMultipleItemRvAdapter;
import com.heifeng.cloudshelf.mvp.programme.adapter.SpecTextRvAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2019/9/19.
 */

public class SpecItemProvider extends BaseItemProvider<SpecMultipleEntity, BaseViewHolder> {
    private List<ProgrammeSelectInfo> infos;

    private LinearLayoutManager layoutManager;

    private SpecTextRvAdapter adapter;

    private List<ProgrammeSelectInfo.OptionBean> tempData = new ArrayList<>();

    public SpecItemProvider(Context context, List<ProgrammeSelectInfo> infos) {
        this.infos = infos;
        mContext = context;
    }

    @Override
    public int viewType() {
        return SpecMultipleItemRvAdapter.TYPE_VIEW;
    }

    @Override
    public int layout() {
        return R.layout.layout_programme_bottom_rv;
    }

    @Override
    public void convert(BaseViewHolder helper, SpecMultipleEntity data, int position) {
        if (infos.size() > data.getPosition()) {
            helper.setImageResource(R.id.iv_icon, infos.get(data.getPosition()).getIcon());
            helper.setText(R.id.tv_title, infos.get(data.getPosition()).getTitle());
            initRecyclerView(helper.getView(R.id.recyclerview), data);
        }
    }

    public void initRecyclerView(RecyclerView recyclerView, SpecMultipleEntity data) {
        int size = infos.get(data.getPosition()).getOptions().size();
        if (size > 9) {
            tempData = infos.get(data.getPosition()).getOptions().subList(0, 9);
        } else
            tempData = infos.get(data.getPosition()).getOptions();

        layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
        recyclerView.setLayoutManager(layoutManager);
        adapter = new SpecTextRvAdapter(mContext, R.layout.layout_programme_bottom_string_item, tempData, infos, size, data.getPosition());
        recyclerView.setAdapter(adapter);
    }


}
